-
-
Notifications
You must be signed in to change notification settings - Fork 398
Use a local Walk function #421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Because arduino-cli segfaults when sketchDir is a symbolic link, a simple walk function is introduced with a twofold effect: - fix the segfault - allow to use symlinks ref: https://www.google.com/search?q=golang+Walk+does+not+follow+symbolic+links
Hi @d-a-v, thank for your submission. We already have an implementation of the "walk-folllowing-symlinks" here: BTW, I was wondering why the golang This seems to be not golang-related but also other language that allows following symlinks suffer the same problem, for example in python we have: https://docs.python.org/3/library/os.html#os.walk that warns:
Since it seems that there isn't a saner/simple way to avoid loop we want to propose the following solution:
this should cover the use cases in #424 (and I think 99.99% of the overall use cases). |
Thanks, I'm happy to close this PR when #424 is fixed by another mean. (edited) About the walking issue with symbolic links, we can add a decreasing counter in the recursive walk function (like the factorial recursive function we learn at school), and return an error (like I've also read the golang issues in their repository and I just don't understand why or how they would rewrite (or avoid) the unix features their own way. A symbolic link loop is on user responsibility Golang sys lib's responsibility is only to not fail (heap here), not to remove any OS functionality IMHO.
|
Hi @d-a-v , We want to use your PR as a starting point to introduce a more robust As a second step, we will make the Thanks for your help! |
I'd be glad to. First I need to know whether you agree with the idea that a path depth shall not be more than a given constant (like 40, similar to what's done in linux kernel Shall I make this proposal over this file (instead of mine) ? Is it intended to stay where it is ? |
My 2c:
|
- act on error in walk function (OS can detect symbolic links loops (lnk -> lnk)) - add a deepness detector for non trivial loops (dir/lnk -> ../..)
Testing the error was missing in the user walk function, A reference to this issue is added in a comment about the discussion on |
How to test this code (with linux):
(OS error printed) Or not detectable by OS:
(depth detection error) |
Maybe we should differentiate two cases here:
Here the tricky case (2):
it seems that |
These two cases are handled by this PR. About |
arduino/builder/sketch.go
Outdated
} | ||
|
||
// SimpleLocalWalk locally replaces filepath.Walk and/but goes through symlinks | ||
func SimpleLocalWalk(root string, walkFn func(path string, info os.FileInfo, err error) error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The simpleLocalWalkRecursive()
is currently used in this module only, There's no need to wrap it and export it. Can you please remove the wrapper and use directly simpleLocalWalkRecursive()
?
Regarding the maxDepth
param, can you please create a private constant in this module (named for example maxFileSystemDepth) documenting it properly writing something like: As currently implemented on Linux, the maximum number of symbolic links that will be followed while resolving a pathname is 40
? This way you can use something more meaningful as a parameter when calling the function.
Thanks!
Hi @d-a-v! I left a comment on your code. |
arduino/builder/sketch.go
Outdated
err = SimpleLocalWalk(sketchFolder, func(path string, info os.FileInfo, err error) error { | ||
|
||
if err != nil { | ||
fmt.Printf("\nerror: %+v\n\n", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use the /cli/feedback
package to print error messages like
feedback.Errorf("Error ....: %v", err)
@rsora I think I addressed your review. |
@d-a-v can you try manually running |
@masci I don't understand CI messages though. |
What about a script to run before pushing changes that would run CI tests locally ? |
@d-a-v our contributing guidelines already explain how to run tests locally before pushing code: https://github.com/arduino/arduino-cli/blob/master/CONTRIBUTING.md#running-the-tests The style check, |
Hi @d-a-v , left a comment regarding the error management. |
Co-Authored-By: Roberto Sora <[email protected]>
fixes addressed, CI passed, thanks for your feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent! 👍
Because arduino-cli segfaults when sketchDir is a symbolic link,
a simple walk function is introduced with a twofold effect:
ref: https://www.google.com/search?q=golang+Walk+does+not+follow+symbolic+links
edit: